package com.s666.demo.common.enums;

/**
 * 枚举可表示多个值
 */
public enum  TestEnum {
    INIT(1, "初始", "init"),
    SUCCESS(6, "成功", "success"),
    FAIL(11, "失败", "fail");

    private int code;
    private String symbol;
    private String name;

    /**
     * 参数的顺序必须与INIT(1, "初始", "init")的一致
     * @param code
     * @param name
     * @param symbol
     */
    TestEnum(int code, String name, String symbol) {
        this.code = code;
        this.name = name;
        this.symbol = symbol;
    }

    public int getCode() {
        return code;
    }

    public String getName() {
        return name;
    }

    public String getSymbol() {
        return symbol;
    }

    /**
     * 根据符号获取
     *
     * @param symbol
     * @return TestEnum
     */
    public static TestEnum getBySymbol(String symbol) {
        switch (symbol) {
            case "init":
                return INIT;
            case "success":
                return SUCCESS;
            case "fail":
                return FAIL;
            default:
                return null;
        }
    }

    @Override
    public String toString() {
        return "TestEnum{" +
                "code=" + code +
                ", name='" + name + '\'' +
                ", symbol='" + symbol + '\'' +
                '}';
    }
}
